#ifndef __GYBMP280_H__
	#define __GYBMP280_H__
	
	#include <stdio.h>
	#include <unistd.h>
	#include <stdbool.h>
	#include <math.h>
	#include "ohos_init.h"
	#include "cmsis_os2.h"
	#include "wifiiot_gpio.h"
	#include "wifiiot_gpio_ex.h"
	#include "wifiiot_i2c.h"
	#include "wifiiot_i2c_ex.h"

	//从设备地址
	#define GYBMP280_DEVICE_ADDRESS				0x76
	
	//状态寄存器转换标志
	#define	GYBMP280_MEASURING					0x01
	#define	GYBMP280_IM_UPDATE					0x08
	
	//复位寄存器写入值
	#define GYBMP280_RESET_VALUE				0xB6
	
	//要用的矫正数据寄存器
	#define GYBMP280_DIG_T1_LSB_REG				0x88
	#define GYBMP280_DIG_T1_MSB_REG				0x89
	#define GYBMP280_DIG_T2_LSB_REG				0x8A
	#define GYBMP280_DIG_T2_MSB_REG				0x8B
	#define GYBMP280_DIG_T3_LSB_REG				0x8C
	#define GYBMP280_DIG_T3_MSB_REG				0x8D
	#define GYBMP280_DIG_P1_LSB_REG				0x8E
	#define GYBMP280_DIG_P1_MSB_REG				0x8F
	#define GYBMP280_DIG_P2_LSB_REG				0x90
	#define GYBMP280_DIG_P2_MSB_REG				0x91
	#define GYBMP280_DIG_P3_LSB_REG				0x92
	#define GYBMP280_DIG_P3_MSB_REG				0x93
	#define GYBMP280_DIG_P4_LSB_REG				0x94
	#define GYBMP280_DIG_P4_MSB_REG				0x95
	#define GYBMP280_DIG_P5_LSB_REG				0x96
	#define GYBMP280_DIG_P5_MSB_REG				0x97
	#define GYBMP280_DIG_P6_LSB_REG				0x98
	#define GYBMP280_DIG_P6_MSB_REG				0x99
	#define GYBMP280_DIG_P7_LSB_REG				0x9A
	#define GYBMP280_DIG_P7_MSB_REG				0x9B
	#define GYBMP280_DIG_P8_LSB_REG				0x9C
	#define GYBMP280_DIG_P8_MSB_REG				0x9D
	#define GYBMP280_DIG_P9_LSB_REG				0x9E
	#define GYBMP280_DIG_P9_MSB_REG				0x9F
	
	#define GYBMP280_CHIPID_REG					0xD0  	/*Chip ID Register */
	#define GYBMP280_RESET_REG					0xE0  	/*Softreset Register */
	#define GYBMP280_STATUS_REG					0xF3  	/*Status Register */
	#define GYBMP280_CTRLMEAS_REG				0xF4  	/*Ctrl Measure Register */
	#define GYBMP280_CONFIG_REG					0xF5  	/*Configuration Register */
	#define GYBMP280_PRESSURE_MSB_REG			0xF7  	/*Pressure MSB Register */
	#define GYBMP280_PRESSURE_LSB_REG			0xF8  	/*Pressure LSB Register */
	#define GYBMP280_PRESSURE_XLSB_REG			0xF9  	/*Pressure XLSB Register */
	#define GYBMP280_TEMPERATURE_MSB_REG		0xFA  	/*Temperature MSB Reg */
	#define GYBMP280_TEMPERATURE_LSB_REG		0xFB  	/*Temperature LSB Reg */
	#define GYBMP280_TEMPERATURE_XLSB_REG		0xFC  	/*Temperature XLSB Reg */
	
	typedef enum {DISABLE = 0, ENABLE = 1} FunctionalState;

	//BMP工作模式
	typedef enum {
		GYBMP280_SLEEP_MODE  = 0x00,
		GYBMP280_FORCED_MODE = 0x01,
		GYBMP280_NORMAL_MODE = 0x03
	} GYBMP280_WORK_MODE;

	//BMP压力过采样因子
	typedef enum 
	{
		GYBMP280_P_MODE_SKIP = 0x00,/*skipped*/
		GYBMP280_P_MODE_1,			/*x1*/
		GYBMP280_P_MODE_2,			/*x2*/
		GYBMP280_P_MODE_3,			/*x4*/
		GYBMP280_P_MODE_4,			/*x8*/
		GYBMP280_P_MODE_5			/*x16*/
	} GYBMP280_P_OVERSAMPLING;	

	//BMP温度过采样因子
	typedef enum {
		GYBMP280_T_MODE_SKIP = 0x00,/*skipped*/
		GYBMP280_T_MODE_1,			/*x1*/
		GYBMP280_T_MODE_2,			/*x2*/
		GYBMP280_T_MODE_3,			/*x4*/
		GYBMP280_T_MODE_4,			/*x8*/
		GYBMP280_T_MODE_5			/*x16*/
	} GYBMP280_T_OVERSAMPLING;
										
	//IIR滤波器时间常数
	typedef enum {
		GYBMP280_FILTER_OFF = 0x00,	/*filter off*/
		GYBMP280_FILTER_MODE_1,		/*0.223*ODR*/	/*x2*/
		GYBMP280_FILTER_MODE_2,		/*0.092*ODR*/	/*x4*/
		GYBMP280_FILTER_MODE_3,		/*0.042*ODR*/	/*x8*/
		GYBMP280_FILTER_MODE_4		/*0.021*ODR*/	/*x16*/
	} GYBMP280_FILTER_COEFFICIENT;

	//保持时间
	typedef enum {
		GYBMP280_T_SB1 = 0x00,		/*0.5ms*/
		GYBMP280_T_SB2,				/*62.5ms*/
		GYBMP280_T_SB3,				/*125ms*/
		GYBMP280_T_SB4,				/*250ms*/
		GYBMP280_T_SB5,				/*500ms*/
		GYBMP280_T_SB6,				/*1000ms*/
		GYBMP280_T_SB7,				/*2000ms*/
		GYBMP280_T_SB8,				/*4000ms*/
	} GYBMP280_T_SB;

	typedef struct  
	{
		/* T1~P9 为补偿系数 */
		uint16_t T1;
		int16_t	 T2;
		int16_t	 T3;
		uint16_t P1;
		int16_t	 P2;
		int16_t	 P3;
		int16_t	 P4;
		int16_t	 P5;
		int16_t	 P6;
		int16_t	 P7;
		int16_t	 P8;
		int16_t	 P9;
	} GYBMP280_COMPENSATION_COEFFICIENT;

	typedef struct
	{
		GYBMP280_P_OVERSAMPLING 	P_Osample;
		GYBMP280_T_OVERSAMPLING 	T_Osample;
		GYBMP280_WORK_MODE			WORKMODE;
	} GYBMP280_OVERSAMPLE_MODE;
		
	typedef struct
	{
		GYBMP280_T_SB 				T_SB;
		GYBMP280_FILTER_COEFFICIENT	FILTER_COEFFICIENT;
		FunctionalState				SPI_EN;
	} GYBMP280_CONFIG;

	extern GYBMP280_COMPENSATION_COEFFICIENT *GYBMP280_Compensation_Coefficient;
	
	/*******************************下面是用来计算补偿值相关**********************************/
	typedef			long signed int				S32_t;	//有符号 32位！
	typedef			long unsigned int			U32_t;	//无符号 32位！
	typedef			long long signed int		S64_t;	//有符号 64位！

	#define	dig_T1	GYBMP280_Compensation_Coefficient->T1
	#define	dig_T2	GYBMP280_Compensation_Coefficient->T2
	#define	dig_T3	GYBMP280_Compensation_Coefficient->T3
	#define	dig_P1	GYBMP280_Compensation_Coefficient->P1
	#define	dig_P2	GYBMP280_Compensation_Coefficient->P2
	#define	dig_P3	GYBMP280_Compensation_Coefficient->P3
	#define	dig_P4	GYBMP280_Compensation_Coefficient->P4
	#define	dig_P5	GYBMP280_Compensation_Coefficient->P5
	#define	dig_P6	GYBMP280_Compensation_Coefficient->P6
	#define	dig_P7	GYBMP280_Compensation_Coefficient->P7
	#define	dig_P8	GYBMP280_Compensation_Coefficient->P8
	#define	dig_P9	GYBMP280_Compensation_Coefficient->P9
	/************************************************CUT****************************************/
	
	void GYBMP280_Init(void);
	
	//获取GYBMP280当前状态
	//参数：GYBMP280_MEASURING || GYBMP280_IM_UPDATE
	//返回：true成功，false失败
	bool GYBMP280_GetStatus(uint8_t statusFlag);
	
	//获取大气温度值单位：℃
	double GYBMP280_GetAtmosphericTemperature(void);

	//获取大气压强值单位：Pa
	double GYBMP280_GetAtmosphericPressure(void);

	//获取海拔高度值单位：ｍ
	double GYBMP280_GetAltitude(void);
#endif
